/***************************************************************************\
 * The Mattise Kernel														*
 * Copyright 2007 Matthew Iselin											*
 * Licensed under the GPL													*
 *																			*
 * vesa.cc																	*
 *																			*
 * VESA mode switcher.														*
 *																			*
\***************************************************************************/

#include <system.h>
#include <stdio.h>
#include <task.h>
#include <filesys.h>

// enters a VBE mode, returns the LFB address
uint_t EnterVesaMode( ushort_t xres, ushort_t yres, ushort_t bpp ) 
{
	// enter the wanted mode
	struct regs r;
	r.eax = xres;
	r.ebx = yres;
	r.ecx = bpp;
	
	// load the vbe switcher - TODO: this should be in a seperate file, in userland...
	FILE fp = fopen( "dr0/vbe.sys", "r" );
	
	// check if it is valid
	fread( (void*) 0x1000, 0, fp.size, fp );
	
	// start it
	int p = CreateTask16bit( 0x1000, 1024, "VBE Mode Switcher", &r );
	
	// wait for it
	WaitUntilComplete( p );
	
	// get it's registers
	GetRegs( p, &r );
	
	// close the file
	fclose( fp );
	
	// return the LFB address
	return r.ecx;
}
